import http from "@/api/index";

// 文件列表
export const getMediaList = data => {
  return http.get(`/media/list`, data);
};

// 上传文件
export const addMedia = (data, onProgress?) => {
  return http.post(`/media/upload`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    },
    onUploadProgress: e => {
      if (e.total) {
        onProgress({ percent: Math.round((e.loaded * 100) / e.total) });
      }
    }
  });
};

// 查看文件
export const getMedia = id => {
  return http.post(`/media/viewid?id=${id}`);
};

// 文件详情
export const detailMedia = id => {
  return http.get(`/media/detail?id=${id}`);
};

// 下载文件
export const downloadMedia = id => {
  return http.post(`/media/download?id=${id}`);
};

// 删除文件
export const delMedia = id => {
  return http.delete(`/media/delete?id=${id}`);
};

// 检查md5是否存在
export const checkMd5Media = id => {
  return http.post(`/media/check-md5?id=${id}`);
};
